home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 23.8 KB | 1,168 lines | [TEXT/MPS ] |
- /*
- File: CTBChannel.cp
-
- Contains: xxx put contents here xxx
-
- Written by: Tim Harnett
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <33> 3/6/95 TMH adapt to use Symantic compiler
- <32> 2/27/95 TMH adapt to use ETO16 universal headers
- <31> 2/21/95 TMH metrowerks compatiblity changes
- <30> 2/15/95 TMH moved gEnableIOTrace
- <29> 12/16/94 TMH fix so no error is logged when server not available
- <28> 12/12/94 TMH use of gCurrentThread->Yield()
- <27> 11/17/94 TMH fixes to wakeup thread
- <26> 11/10/94 TMH use StopForIO
- <25> 11/8/94 TMH changes to support async P3 thread
- <24> 11/2/94 JHB Adding support for Sending eWorld Mail
- <23> 11/2/94 TMH IO trace stuff
- <22> 11/2/94 TMH added no carrier detect stuff, and WriteBytes
- <21> 10/28/94 TMH Open, Read etc return osErr instead of fail
- <20> 10/28/94 TMH made async and X25 work better
- <19> 10/26/94 TMH some tweaks with the asynchronous stuff
- <18> 10/25/94 TMH made open,close, read & write asynchronous
- <15> 10/24/94 JHB Correct CMRead ASSERT
- <14> 10/21/94 TMH created TModemChannel and TX25Channel
- <12> 10/20/94 TMH cleaned up ICTBChannel
- <11> 10/20/94 TMH cleaned up ICTBChannel
- <10> 10/18/94 TMH pass external slot to ICTBChannel, some clean up
- <10> 10/18/94 TMH pass external slot to ICTBChannel, some clean up
-
- To Do:
- */
-
-
- #ifndef __ERRORS__
- #include "Errors.h"
- #endif
-
- #include <String.h>
- #include <Strings.h>
- #include <StdIO.h>
-
-
- #ifndef __RESOURCES__
- #include "Resources.h"
- #endif
-
- #ifndef __CRecordID__
- #include "CRecordID.h"
- #endif
-
- #ifndef __CommonResources__
- #include "CommonResources.h"
- #endif
-
- #ifndef __CResourceIterator__
- #include "CResourceIterator.h"
- #endif
-
- #ifndef __CAttribute__
- #include "CAttribute.h"
- #endif
-
- #ifndef __PMSAMResources__
- #include "PMSAMResources.h"
- #endif
-
- #ifndef __PMSAMResourceIds__
- #include "PMSAMResourceIDs.h"
- #endif
-
- #ifndef _CTBCHANNEL_
- #include "CTBChannel.h"
- #endif
-
- #ifndef __MSAMSlot__
- #include "MSAMSlot.h"
- #endif
-
- #ifndef __Debug__
- #include "Debug.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __TThread__
- #include "TThread.h"
- #endif
- #ifndef __Globals__
- #include "Globals.h"
- #endif
-
- extern Boolean gEnableIOTrace; // set from resource
- CFile gReadCaptureFile;
- CFile gWriteCaptureFile;
-
- void EnableIOCapture(); // the compiler insists!
- void EnableIOCapture()
- {
-
- Str255 uniqueName;
- long now = TickCount();
- CFolder traceFolder;
-
- OSErr osErr = FocHFSHeirarchyFromResource(kTraceFolderResID,traceFolder);
- ASSERTNOERR(osErr);
- if( osErr == 0 ) {
-
- FileSpecResource** fileSpec = (FileSpecResource**)::GetResource('file',kReadCaptureFileResID);
- ASSERT(fileSpec);
- if( fileSpec == 0 )
- return;
-
-
- uniqueName[0] = sprintf((char*)&uniqueName[1],"%.20P%08x",(*fileSpec)->filename,now); // concat time stamp with name.
- gReadCaptureFile.SetFSSpec(-1,traceFolder.DirID(),uniqueName);
- OSErr osErr = gReadCaptureFile.Create((*fileSpec)->fileCreator,(*fileSpec)->fileType);
- ASSERTNOERR(osErr);
- osErr = gReadCaptureFile.Open(fsWrPerm);
- ASSERTNOERR(osErr);
-
-
- fileSpec = (FileSpecResource**)::GetResource('file',kWriteCaptureFileResID);
- ASSERT(fileSpec);
- if( fileSpec == 0 )
- return;
-
-
- uniqueName[0] = sprintf((char*)&uniqueName[1],"%.20P%08x",(*fileSpec)->filename,now); // concat time stamp with name.
- gWriteCaptureFile.SetFSSpec(-1,traceFolder.DirID(),uniqueName);
- osErr = gWriteCaptureFile.Create((*fileSpec)->fileCreator,(*fileSpec)->fileType);
- ASSERTNOERR(osErr);
- osErr = gWriteCaptureFile.Open(fsWrPerm);
- ASSERTNOERR(osErr);
-
-
-
- }
-
-
-
- }
-
-
- //----------------------------------------
- // TCTBChannel
- //----------------------------------------
-
- #pragma segment CTBChannel
-
- TCTBChannel::TCTBChannel ()
- {
-
- fExternalSlot = 0;
- fConnH = 0;
- fWakeupThread = 0;
-
-
- // Configuration -- will be overridden by resource values
-
-
- fReadTimeout = -1;
- fWriteTimeout = -1;
- fOpenTimeout = -1;
- fCloseTimeout = -1;
-
- fOpenASync = kDoSync;
- fCloseASync = kDoSync;
- fReadASync = kDoSync;
- fWriteASync = kDoSync;
-
- fConfigBufSize = 512;
-
-
- fBaudRate = 2400; // default baud setting, lowest usable
-
-
- memset(&fConnEnvironRec, 0, sizeof(ConnEnvironRec));
-
- for( CMBufFields theCurrField = cmDataIn; theCurrField <= cmRsrvOut; theCurrField++)
- fBufferSizesArray[theCurrField] = 0;
-
-
- fBufferSizesArray[cmDataIn] = fBufferSizesArray[cmDataOut] = 1024;
- }
-
-
-
- //------------------------------------------------------------------------------------
- TCTBChannel::~TCTBChannel ()
- {
-
- if (fConnH != 0 )
- CMDispose(fConnH);
-
- if( fWakeupThread != 0 ) {
- ASSERT(fWakeupThread->GetThreadState() == kStoppedThreadState);
- delete fWakeupThread;
- }
-
- if( fCTBIdleThread != 0 ) {
- ASSERT(fCTBIdleThread->GetThreadState() == kStoppedThreadState);
- delete fCTBIdleThread;
- }
-
- }
-
-
-
- //------------------------------------------------------------------------------------
- void TCTBChannel::ICTBChannel(short toolParamResID,StringPtr toolName, TExternalSlot* exSlot)
- {
-
- ASSERT(exSlot);
-
-
- FailInfo fi;
- Try(fi)
- {
- fExternalSlot = exSlot;
-
- this->SetCTBParametersFromResource(toolParamResID);
-
-
- this->InitializeCTB();
-
- short theToolProcID = CMGetProcID(toolName);
- ASSERT( theToolProcID != -1 );
- if (theToolProcID == -1)
- FailOSErr(errUnableToInitCTB);
-
-
- CMRecFlags theCMFlags = cmData + cmQuiet + cmNoMenus;
- long myRefCon = 0;
- long myUserData = 0;
-
- fConnH = CMNew (theToolProcID, theCMFlags, fBufferSizesArray, myRefCon, myUserData);
- if(!fConnH) {
- ASSERT( fConnH != 0 );
- FailMemError();
- }
-
-
- // The wakeup thread for async IO.
-
-
- TWakeupThread* wakeupThread = new TWakeupThread;
- wakeupThread->IWakeupThread();
- fWakeupThread = wakeupThread;
-
-
- // Idle thread -- to assure that CMIdle is called.
-
- TCTBIdleThread* idleThread = new TCTBIdleThread;
- idleThread->ICTBIdleThread(this);
- fCTBIdleThread = idleThread;
-
- CMSetRefCon(fConnH,(long) this);
-
- // If we'll be capturing get a file for it.
-
- if( gEnableIOTrace )
- ::EnableIOCapture();
-
- fi.Success();
-
- } else {
-
- delete this;
- fi.ReSignal();
-
- }
-
- return;
- }
-
-
-
- //------------------------------------------------------------------------------------
- void TCTBChannel::Waitfor( short time)
- {
- long t=0;
- long timeout;
-
- timeout = TickCount()+time;
- while (TickCount()<timeout) ++t;
-
- }
-
-
-
- //---------------------------------------------------------------
- void TCTBChannel::InitializeCTB()
- {
- CMErr theCMErr = InitCM();
- ASSERTNOERR(theCMErr);
-
- if( theCMErr != 0 )
- FailOSErr(errUnableToInitCTB);
-
-
- CTBUErr theCTBErr = InitCTBUtilities();
- ASSERTNOERR(theCTBErr);
- if( theCTBErr != 0 )
- FailOSErr(errUnableToInitCTB);
-
- }
-
-
-
- //--------------------------------------------------------------------------------------
- OSErr TCTBChannel::Connect(Ptr configString)
- {
- ASSERT(configString);
- ASSERT( fCommState != sConnected);
- ASSERT( fCommState != sConnecting );
-
-
- FailInfo fi;
- Try(fi) {
-
- fCTBIdleThread->StartThread();
-
- short setConfigErr = CMSetConfig(fConnH, configString);
- ASSERT(setConfigErr==0);
- if(setConfigErr)
- FailOSErr(errCommConfigParamMissingOrCorrupt);
-
-
- Boolean hConnValid = CMValidate(fConnH); // gratuitous
- ASSERTNOERR(hConnValid);
-
-
- FailOSErr( this->Open() );
-
-
- fConnEnvironRec.version = curConnEnvRecVers;
- CMErr cmErr = CMGetConnEnvirons(fConnH, &fConnEnvironRec);
- ASSERTNOERR(cmErr);
- FailOSErr(cmErr);
-
-
- this->NetworkLogin();
-
- fCommState = sConnected;
-
-
- fi.Success();
-
-
- } else {
-
- if( ::IsCTBError(fi.error) )
- fi.error = errCantOpenCTBConnection; // what will be reported to the user.
-
-
- this->Close();
- fCTBIdleThread->StopThread();
-
- fCommState = sDisconnected;
-
- }
-
-
- return fi.error;
-
-
- }
-
-
- //---------------------------------------------------------------
- void TCTBChannel::NetworkLogin( )
- {
-
-
- }
-
-
-
- //--------------------------------------------------------------------------------------
- void TCTBChannel::Disconnect()
- {
- while( this->IsIOPending() )
- gCurrentThread->Yield();
-
-
- if( this->IsOpen() ) {
- this->KillAllIO();
- this->Close();
- }
-
- fCTBIdleThread->StopThread();
-
- }
-
-
- //---------------------------------------------------------------------------
- Boolean TCTBChannel::IsIOPending()
- {
- CMStatFlags cmStatus = this->GetCMStatus();
-
-
- CMStatFlags pendingFlags = cmStatusOpening + cmStatusClosing +
- cmStatusDRPend + cmStatusDWPend +
- cmStatusCRPend + cmStatusCWPend +
- cmStatusARPend + cmStatusAWPend +
- cmStatusBreakPend + cmStatusListenPend;
-
-
- // Careful here of the small window of execution where the wakeup thread has been started
- // but has not yet started the threadtoWake, ie. it remains Stopped until IO completion
- // routine is called.
-
-
- return ((cmStatus & pendingFlags) != 0) || fWakeupThread->Busy();
-
-
- }
-
-
- //---------------------------------------------------------------------------
- Boolean TCTBChannel::IsOpen()
- {
- CMStatFlags cmStatus = this->GetCMStatus();
- return (cmStatus & cmStatusOpen) != 0;
- }
-
-
- //---------------------------------------------------------------------------
- Boolean TCTBChannel::IsOpenPending()
- {
-
- CMStatFlags cmStatus = this->GetCMStatus();
-
- // Should we be checking all of these?
-
- return (cmStatus & cmStatusOpening) != 0 || fWakeupThread->Busy();
- }
-
- //---------------------------------------------------------------------------
- Boolean TCTBChannel::IsReadPending()
- {
- CMStatFlags cmStatus = this->GetCMStatus();
-
- return (cmStatus & cmStatusDRPend) != 0 || fWakeupThread->Busy();
- }
-
-
- //---------------------------------------------------------------------------
- Boolean TCTBChannel::IsWritePending()
- {
- CMStatFlags cmStatus = this->GetCMStatus();
-
- return (cmStatus & cmStatusDWPend) != 0 || fWakeupThread->Busy();
- }
-
-
- //---------------------------------------------------------------------------
- long TCTBChannel::DataAvail()
- {
- long datacount = 0;
- CMStatFlags stat;
- CMBufferSizes counts;
-
-
- CMErr cmErr = CMStatus(fConnH, counts, &stat);
- ASSERTNOERR(cmErr);
-
- if( cmErr == 0 )
- datacount = counts[cmDataIn];
-
- return datacount;
- }
-
-
-
- //---------------------------------------------------------------------------
- CMStatFlags TCTBChannel::GetCMStatus()
- {
-
- CMStatFlags statusFlags = 0;
- CMBufferSizes counts;
- CMErr cmErr = CMStatus(fConnH, counts, &statusFlags);
- ASSERTNOERR(cmErr);
-
-
- return statusFlags;
- }
-
-
- //---------------------------------------------------------------------------------
- CMErr TCTBChannel::KillAllIO()
- {
- short allIO = cmDataIn+cmDataOut+cmCntlIn+cmCntlOut+cmAttnIn+cmAttnOut;
-
- CMErr cmErr = CMIOKill(fConnH,allIO);
- ASSERTNOERR(cmErr);
-
- return cmErr;
-
- }
-
-
- //---------------------------------------------------------------------------------
- CMErr TCTBChannel::Abort()
- {
-
- CMErr cmErr = CMAbort(fConnH);
- ASSERTNOERR(cmErr);
-
- return cmErr;
-
- }
-
- //--------------------------------------------------------------------------------------
- void TCTBChannel::FlushRead()
- {
- ASSERT(!this->IsReadPending());
-
- CMErr cmErr =CMIOKill(fConnH, cmDataIn);
-
- ASSERTNOERR(cmErr);
-
- }
-
-
- //--------------------------------------------------------------------------------------
- void TCTBChannel::FlushWrite()
- {
- ASSERT(!this->IsWritePending());
-
- CMErr cmErr =CMIOKill(fConnH, cmDataOut);
- ASSERTNOERR(cmErr);
-
- }
-
-
-
- //--------------------------------------------------------------------------
- CMErr TCTBChannel::Open()
- {
- CMErr cmErr = 0;
-
- if( fOpenASync ) {
-
- fWakeupThread->SetThreadToWake(gCurrentThread);
- ASSERT( fWakeupThread->GetThreadState() == kStoppedThreadState );
-
- CMOpen(fConnH, kDoAsync, &__CTBCompletorProc, this->OpenTimeout());
-
- gCurrentThread->StopForIO();
-
- fWakeupThread->SetThreadToWake(0);
-
- cmErr = (short)(*fConnH)->userData;
-
-
- } else {
-
- cmErr = CMOpen(fConnH, kDoSync, 0, this->OpenTimeout());
-
- }
-
-
- ASSERTNOERR(cmErr);
-
- return cmErr;
-
-
- }
-
-
-
- #pragma segment CTBChannel
- //--------------------------------------------------------------------------
- OSErr TCTBChannel::Close()
- {
- CMErr cmErr = 0;
-
- if( fOpenASync ) {
-
-
- fWakeupThread->SetThreadToWake(gCurrentThread);
- ASSERT( fWakeupThread->GetThreadState() == kStoppedThreadState );
-
- CMClose( fConnH, kDoAsync, &__CTBCompletorProc, this->CloseTimeout(), kDontWaitForPending);
-
- gCurrentThread->StopForIO();
- fWakeupThread->SetThreadToWake(0);
-
- cmErr = (short)(*fConnH)->userData;
-
- } else {
-
- cmErr = CMClose( fConnH, kDoAsync, 0, this->CloseTimeout(), kDontWaitForPending);
-
- }
-
- ASSERTNOERR(cmErr);
-
- return cmErr;
-
- }
-
-
- //-------------------------------------------------------------------------------
- CMErr TCTBChannel::Read( char *theBuffer, long bytesToRead, long timeOut)
- {
- CMErr cmErr = 0;
-
- if( fReadASync ) {
-
- fWakeupThread->SetThreadToWake(gCurrentThread);
- ASSERT( fWakeupThread->GetThreadState() == kStoppedThreadState );
-
- CMRead(fConnH, theBuffer, &bytesToRead, cmData, kDoAsync, &__CTBCompletorProc, timeOut, &fConnEnvironRec.flags);
-
- gCurrentThread->StopForIO();
- fWakeupThread->SetThreadToWake(0);
-
- cmErr = (short)(*fConnH)->userData;
-
-
- } else {
-
- cmErr = CMRead(fConnH, theBuffer, &bytesToRead, cmData, kDoSync, 0, timeOut, &fConnEnvironRec.flags);
-
- }
-
-
- ASSERTNOERR(cmErr);
-
- if( cmErr == 0 && gEnableIOTrace )
- gReadCaptureFile.Write(theBuffer,bytesToRead); // ignore errors
-
-
- return cmErr;
-
- }
-
-
- //-------------------------------------------------------------------------------
- CMErr TCTBChannel::Write( char *theBuffer, long bytesToWrite, long timeOut)
- {
- CMErr cmErr = 0;
-
- if( fWriteASync ) {
-
- fWakeupThread->SetThreadToWake(gCurrentThread);
- ASSERT( fWakeupThread->GetThreadState() == kStoppedThreadState );
-
- CMWrite(fConnH, theBuffer, &bytesToWrite, cmData, kDoAsync, &__CTBCompletorProc,timeOut, fConnEnvironRec.flags);
-
- gCurrentThread->StopForIO();
- fWakeupThread->SetThreadToWake(0);
-
- cmErr = (short)(*fConnH)->userData;
-
- } else {
-
- cmErr = CMWrite(fConnH, theBuffer, &bytesToWrite, cmData, kDoSync, 0 ,timeOut, fConnEnvironRec.flags);
- }
-
-
- ASSERTNOERR(cmErr);
-
-
- if( cmErr == 0 && gEnableIOTrace )
- gWriteCaptureFile.Write(theBuffer,bytesToWrite); // ignore errors
-
-
-
- return cmErr;
-
- }
-
-
-
-
-
- //-------------------------------------------------------------------------------
- void TCTBChannel::WriteBytes( void *theBuffer, long bytesToWrite)
- {
- FailOSErr( this->Write((char*)theBuffer,bytesToWrite,this->WriteTimeout()) );
- }
-
-
-
- //-------------------------------------------------------------------------------
- pascal void TCTBChannel::__CTBCompletorProc(ConnHandle theConnectionHandle)
- {
-
- TCTBChannel* thisChannel = (TCTBChannel*) (*theConnectionHandle)->refCon;
- long a5 = thisChannel->fWakeupThread->GetThreadA5();
- long curA5 = ::SetA5(a5);
-
-
- (*theConnectionHandle)->userData = (*theConnectionHandle)->errCode;
-
- thisChannel->fWakeupThread->StartThreadFromCompletionRoutine();
-
-
- ::SetA5(curA5);
-
-
- }
-
-
-
- //---------------------------------------------------------------------------------
- void TCTBChannel::IdleChannel()
- {
- CMStatFlags flags = this->GetCMStatus();
-
- if( flags != 0 )
- CMIdle(fConnH);
-
-
- }
-
-
- //---------------------------------------------------------------------------------
- char TCTBChannel::ReadByte()
- {
- char c;
- FailOSErr( this->Read(&c ,1,this->ReadTimeout() ) );
- return c;
- }
-
-
- //---------------------------------------------------------------------------------
- void TCTBChannel::ReadBytes(char *theBuffer, long bytesToRead )
- {
- FailOSErr( this->Read(theBuffer,bytesToRead,this->ReadTimeout() ) );
- }
-
-
- //-------------------------------------------------------------------------------
- char TCTBChannel::WaitFor(char waitFor)
- {
-
- char c;
- do {
-
- c = this->ReadByte();
- ASSERTPRINT( c== waitFor,("CTB waiting for %0X, recieived = %0x\n",waitFor,c) );
-
- } while( c != waitFor );
-
- return c;
-
- }
-
-
-
- //-------------------------------------------------------------------------------
- char TCTBChannel::WaitForOneOf(char *searchString)
- {
-
- char c = 0;
- do {
- c = this->ReadByte();
- } while( !strchr(searchString, c) );
-
-
- return c;
-
- }
-
-
- //------------------------------------------------------------------------------
- void TCTBChannel::WaitForString(char* searchString)
- {
-
- char c = 0;
- long matchIndex = 0;
-
- long searchStringLen = strlen(searchString);
-
- while( matchIndex < searchStringLen ) {
-
- c = this->ReadByte();
-
- if ( c == searchString[matchIndex] )
- matchIndex++;
- else if ( c == searchString[0] ) // does it match from the beginning?
- matchIndex = 1;
- else
- matchIndex = 0;
-
-
- }
-
-
- return;
- }
-
-
-
- //------------------------------------------------------------------------------
- void TCTBChannel::SendString(char* sendString)
- {
- unsigned long sendLength = strlen(sendString);
-
- FailOSErr( this->Write( sendString, sendLength, this->WriteTimeout()) );
-
- }
-
-
-
-
- //-------------------------------------------------------------------------------------
- void TCTBChannel::SetCTBParametersFromResource(short resID)
- {
-
- CommParameterResource** commParams = (CommParameterResource**)::Get1Resource('ctbp',resID);
- FailNILResource((Handle)commParams);
-
-
- fReadTimeout = (*commParams)->readTimeout == -1 ? -1 : (*commParams)->readTimeout*60;
- fWriteTimeout = (*commParams)->writeTimeout == -1 ? -1 : (*commParams)->writeTimeout*60;
- fOpenTimeout = (*commParams)->openTimeout == -1 ? -1 : (*commParams)->openTimeout*60;
- fCloseTimeout = (*commParams)->closeTimeout == -1 ? -1 : (*commParams)->closeTimeout*60;
-
- fOpenASync = ((*commParams)->flags & kOpenASync) != 0;
- fCloseASync = ((*commParams)->flags & kCloseASync) != 0;
- fReadASync = ((*commParams)->flags & kReadASync) != 0;
- fWriteASync = ((*commParams)->flags & kWriteASync) != 0;
-
-
- fConfigBufSize = (*commParams)->configStrBufSize;
-
-
- fBaudRate = (*commParams)->minimumBaudRate;
-
- ReleaseResource((Handle)commParams);
-
- }
-
-
-
- //---------------------------------
- // T M o d e m C h a n n e l
- //---------------------------------
-
-
- //----------------------------------------------------------
- TModemChannel::TModemChannel()
- {
- fAccessNetwork = SPRINTNET;
-
- fNoCarrierDetectRefNum = 0;
- fNoCarrierDetected = false;
-
-
- }
-
- //----------------------------------------------------------
- void TModemChannel::IModemChannel(StringPtr toolName, TExternalSlot* exSlot)
- {
-
- this->ICTBChannel(kModemToolParams,toolName, exSlot);
-
-
- // NO CARRIER Filter
- Str255 noCarrierStr;
- GetIndString(noCarrierStr, kCTBStreamSearchStrings, kNoCarrierStr);
- FailResError();
- fNoCarrierDetectRefNum = CMAddSearch(fConnH,noCarrierStr,0,NoCarrierDetectProc);
-
-
- }
-
-
-
- //----------------------------------------------------------
- void TModemChannel::MakeConnection()
- {
- Ptr configStr = 0;
-
- FailInfo fi;
- Try(fi) {
-
-
- long buffSize = fConfigBufSize;
- configStr = NewPtr( buffSize );
- FailMemError();
- VOLATILE(configStr);
-
-
- // Read the attribute that holds the config string.
- Handle rsrc = ::Get1Resource('rstr',kCTBConfigStrAttrTypeResID);
- FailNILResource(rsrc);
- CAttributeType configStrAttrType( (RStringHandle)rsrc);
-
-
- OSErr osErr = fExternalSlot->ReadSlotAttribute(configStrAttrType,configStr ,buffSize);
- FailOSErr(osErr);
-
-
- FailOSErr (this->Connect(configStr) );
-
- if(configStr != 0 )
- DisposePtr(configStr);
-
- fi.Success();
-
- } else {
-
- if(configStr != 0 )
- DisposePtr(configStr);
-
- fi.ReSignal();
-
- }
-
-
- }
-
- //------------------------------------------------------------------------------
- void TModemChannel::NetworkLogin( )
- {
- switch(fAccessNetwork) {
-
- case SPRINTNET:
- this->SprintNetLogin();
- break;
-
- default:
- // if no network, we assume we are connecting direectly to an eWorld modem, no nmetwork login necessary
- break;
-
- };
-
- this->WaitForString("CONNECT");
-
-
- }
-
-
-
- //-------------------------------------------------------------------------------
- pascal void TModemChannel::NoCarrierDetectProc(ConnHandle hConn,Ptr /*matchPtr*/, long /*refNum */)
- {
-
- TModemChannel* thisChannel = (TModemChannel*) (*hConn)->refCon;
- thisChannel->fNoCarrierDetected = true;
-
- }
-
-
- //------------------------------------------------------------------------------
- void TModemChannel::SprintNetLogin ()
- {
-
- this->Waitfor(300); // ••Hack•• Cant explain why this is necessary but without it we do not connect, JB
-
- if (this->fBaudRate <= 2400)
- this->SendString("\x0D\x44\x0D");
- else
- this->SendString("@D\x0D");
-
-
- char c = this->WaitForOneOf("?=@");
- switch ( c ) {
-
- case '@': // we're at Sprintnet's command prompt
- break;
-
- case '=': // support update_800 connections
-
- this->SendString("D1\x0D");
-
- c = this->WaitForOneOf( "?=@");
- switch ( c ) {
-
- case '@':
- break;
-
- case '=':
- this->SendString("703,555\x0D");
- this->WaitForOneOf("@");
- break;
-
- case '?':
- ASSERTPRINT(false,("Gotta ? in TModemChannel::SprintnetLogin ") );
- FailOSErr(errCantOpenCTBConnection);
- break;
-
- default: // should NEVER happen
- ASSERTPRINT(false,("Gotta unexpected char in TModemChannel::SprintnetLogin "));
- FailOSErr(errCantOpenCTBConnection);
- break;
- };
-
- break;
-
- case '?':
- ASSERTPRINT(false,("Gotta ? in TModemChannel::SprintnetLogin "));
- FailOSErr(errCantOpenCTBConnection);
- break;
-
- default: // should NEVER happen
- ASSERTPRINT(false,("Gotta ? in TModemChannel::SprintnetLogin "));
- break;
-
- }
-
-
- // if we get here, we're at Sprint's command prompt... send our connection address */
- this->FlushRead();
-
- Handle rsrc = ::Get1Resource('cstr',kSprintConnectAddrResID);
- FailNILResource(rsrc);
- char addrBuf[256];
- BlockMove((Ptr)*rsrc,(Ptr)addrBuf,strlen((char const *)*rsrc)+1);
-
- this->SendString(addrBuf);
- fCommState = sConnecting;
-
-
-
- return;
- }
-
-
-
- //---------------------------------
- // T X 2 5 C h a n n e l
- //---------------------------------
-
-
-
- //----------------------------------------------------------
- TX25Channel::TX25Channel()
- {
- }
-
-
- //----------------------------------------------------------
- void TX25Channel::IX25Channel(StringPtr toolName, TExternalSlot* exSlot)
- {
- this->ICTBChannel(kX25ToolParams,toolName, exSlot);
-
- }
-
- //----------------------------------------------------------
- void TX25Channel::NetworkLogin( )
- {
-
- fCommState = sConnecting;
- char charFound = this->WaitForOneOf("\x11");
-
- }
-
- //----------------------------------------------------------
- void TX25Channel::MakeConnection()
- {
-
- // We try every 'mpad' resource before giving up. There is a
- // 'mpad' resource for every MacX25 server we should try.
-
-
- Ptr configStr = 0;
-
- FailInfo fi;
- Try(fi) {
-
- long buffSize = fConfigBufSize;
- configStr = NewPtr( buffSize ); // Caller is responsible for Disposing.
- FailMemError();
- VOLATILE(configStr);
-
-
- OSErr osErr = errCommConfigParamMissingOrCorrupt; // in case there are NO 'mpad' resources
- CResourceIterator iter('mpad');
- for( Handle rsrc = iter.FirstResource(); iter.More(); rsrc = iter.NextResource() ) {
-
- strcpy((char*)configStr,(char*)*rsrc);
- osErr = this->Connect(configStr);
- if( osErr == 0 )
- break;
-
- // else try the next server...
- extern Boolean gAssertsEnabled;
- if( gAssertsEnabled ) {
- Str255 rsrcName;
- rsrcName[0] = 0;
- short resID;
- ResType resType;
- GetResInfo(rsrc,&resID,&resType,rsrcName);
- ASSERTPRINT(false,("MacX25Server %P not available.\n",rsrcName) );
- }
-
-
- }
-
- FailOSErr(osErr);
-
-
-
- if(configStr != 0 )
- DisposePtr(configStr);
-
-
- fi.Success();
-
-
- } else {
-
- if(configStr != 0 )
- DisposePtr(configStr);
-
-
- fi.ReSignal();
-
- }
-
-
- }
-
-
-
- //-------------------------------------
- // T C T B I d l e T h r e a d
- //--------------------------------------
-
-
- //-------------------------------------------------------------------------------
- TCTBIdleThread::TCTBIdleThread()
- {
-
- fCTBChannel = 0;
- }
-
-
- //-------------------------------------------------------------------------------
- void TCTBIdleThread::ICTBIdleThread(TCTBChannel* ctbChannel)
- {
- this->ICooperativeThread('cidl',kCTBIdleThreadStackSize,kNewSuspend); // start in ::Connect
- fCTBChannel = ctbChannel;
- }
-
- //-------------------------------------------------------------------------------
- void* TCTBIdleThread::ThreadMain()
- {
-
- while( true ) {
-
- FailInfo fi;
- Try(fi) {
- fCTBChannel->IdleChannel();
- this->Yield();
- fi.Success();
- }
-
- }
-
- return this;
- }
-
-